<?php

/**
 * JingYao-backend
 *
 * @link     https://gitee.com/wang-zhihui-release/jingyao-backend
 * @apiDocument https://gitee.com/wang-zhihui-release/jingyao-backend/wikis/
 */

namespace App\Http\Controllers;

use App\Services\CosService;
use App\Services\HttpService;
use Illuminate\Http\Request;

class DevController extends Controller
{
    public function devGet(Request $changeUserRequest, HttpService $httpService)
    {
        $res = $httpService->get('https://api.zhanxindongyao.com/articles/list?type=18&page=1&page_size=10&platform=web');
        return renderSuccessJson(json_decode($res, true));
    }

    public function devPost(Request $request)
    {
        $data = [
            'request_data' => $request->all(),
        ];
        return renderSuccessJson($data);
    }

    public function devError(Request $request)
    {
        return renderErrorJson(config('error_code.no_login'), '未登陆');
    }

    public function devUpload(Request $request, CosService $cosService)
    {
        $file = $request->file('file');
        $cosService->uploadFile('test/2021-06-14/', $file);
    }

    public function pullTestAdmin()
    {
        exec('bash /home/work/script/pull_test_admin.sh', $output);
        return renderSuccessJson($output);
    }

    public function pullTestFe()
    {
        exec('bash /home/work/script/pull_test_fe.sh', $output);
        return renderSuccessJson($output);
    }
}
